﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
 
public partial class HomePage_PrintWholeJJRecord : System.Web.UI.Page
{
    public string _strshow = "block";
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckGoods);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                string _strKey = SysFun.IsSQL(MsgBox.JieMi_Decrypt(Request.QueryString["pid"]));
                if (_strKey == "") return;
                GetTitlesort(_strKey);
            }
            showGridView();
        }
        else
        {
            Response.Write("<script>alert('请登录后再查看！');</script>");
        }
    }

    private void showGridView()
    {
        try
        {
            //HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(Selecttable(), hp1.PageSize);
            //pdes.CurrentPage = hp1.CurrentPage;

            //Session["DT"] = pdes.GetSpecailPage();
            //hp1.RecordCount = pdes.TotalCount;
            Db db = new Db();
            DbPage dbPage = new DbPage(db);
            dbPage.Table = Htable.Value.Split(',')[0].ToString();                                               //要查询的表明
            dbPage.Key = "流水号";                                               //表的主键    
            dbPage.Where = fctConditions();                                           //查询条件    
            dbPage.SelectField = Selecttable();
            dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
            dbPage.PageSize = 10;                                                    //没有显示记录条数   
            dbPage.OrderBy = Htable.Value.Split(',')[1].ToString() == "" ? "流水号" : Htable.Value.Split(',')[1].ToString() + ",流水号";        //排序字段
             
            Session["DT"]  = dbPage.DataTable(30);
     
            dbPage.Db.Close();
            db.Close();
            db = null;
            this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
        }
        catch (Exception em)
        {
            Response.Write("<script>alert('发生异常，请重新登录！');window.close();</script>");
        }
    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    private string fctConditions()//演示临时修改，最后所有字段和查询条件都要重新看
    {
        string strtemp = "   1=1  ", _GoodsId;

        //流水号

        _GoodsId = SysFun.ToTrim(txtGoodsId.Text);

        if (SysFun.IsNumeric(_GoodsId))
        {
            strtemp += "and 流水号 = '" + _GoodsId + "' ";
        }




        //药品名称
        string _strProductName = ProductName.Text.ToString();
        if (_strProductName != "")
        {
            strtemp += "and (通用名 like '%" + _strProductName + "%') ";
        }
        //剂型
        string _strmedio = txtMEDia.Text.ToString();
        if (_strmedio != "")
        {
            strtemp += "and 剂型 like '%" + _strmedio + "%' ";
        }

        //规格
        string _strOutlookc = Outlookc.Text.ToString();
        if (_strOutlookc != "")
        {
            strtemp += "and 规格 like '%" + _strOutlookc + "%' ";
        }


        //挂网企业注册号
        string _strcompanyname_TB = txtCompanyName_tb.Text.ToString();
        if (_strcompanyname_TB != "")
        {
            strtemp += "and 申报企业 like '%" + _strcompanyname_TB + "%' ";
        }


        return strtemp;

    }

    protected void hp1_PageChanging(object sender, HZ.Web.PageChaningEventArgs e)
    {
        showGridView();
    }

    private void GetTitlesort(string _strkey)
    {
        string _strselect = "select ShowSort,pagetitle,MyTatle,MYorderby from show where id=" + _strkey;
        Db db = new Db();
        DataTable dt = db.DataTable(_strselect);
        db.Close();
        if (dt != null && dt.Rows.Count > 0)
        {
            this.Hsort.Value = dt.Rows[0][0].ToString();
            pagetitle.Text = dt.Rows[0][1].ToString();
            if (dt.Rows[0][2] != null && dt.Rows[0][2] != "")
                Htable.Value = dt.Rows[0][2].ToString() + ',' + dt.Rows[0][3].ToString();//要查找的表和排序字段
        }
        dt.Dispose();

    }

    /// <summary>
    /// 根据ID选择显示相应的表
    /// </summary>
    /// <returns></returns>
    private string Selecttable()
    {
        string _strselect = "";
        switch (Hsort.Value.Trim())
        {
            case "0"://产品公示

              //  _strselect = @"select   流水号,  品目号, 通用名, 剂型, 规格, 单位, 系数, 生产企业, 申报企业 from   " + Htable.Value.Split(',')[0].ToString() + fctConditions() + " order by 流水号";
                _strselect = @"流水号,通用名,剂型,规格,单位,系数,包装材质,是否高于国家存储标准,日服量,[是否执行发改价格[2009]]2498号],生产企业,申报企业";
                break;
            case "1":
                break;
            case "2"://挂网公示 
               // _strselect = @"select   通用名,商品名,剂型,包装规格,质量层次,填报企业,生产企业,采购包装价 as 采购价 ,核定零售价,备注,标识,流水号 from   " + Htable.Value.Split(',')[0].ToString() + fctConditions() + " order by zxcg,memo2 asc ,包装规格,质量层次";
                _strselect = @"   通用名,商品名,剂型,包装规格,质量层次,填报企业,生产企业,采购包装价 as 采购价 ,核定零售价,备注,标识,流水号 ";
               break;

            case "3"://其他公示
              //  _strselect = "select * from " + Htable.Value.Split(',')[0].ToString() + " order by " + Htable.Value.Split(',')[1].ToString();
               _strselect = "*";
                break;
        }
        return _strselect;
    }


}
